﻿namespace PvPRogue.Poisons
{
    using CommonBehaviors.Actions;
    using Styx;
    using Styx.CommonBot;
    using Styx.Pathing;
    using Styx.TreeSharp;
    using System.Threading;

    // CREDIT TO CLU (Wulf) and Singular
    public static class Poisons
    {
        public static bool NeedsPoison
        {
            get
            {
                return StyxWoW.Me.Inventory.Equipped.MainHand != null &&
                    StyxWoW.Me.Inventory.Equipped.MainHand.TemporaryEnchantment.Id == 0 &&
                    StyxWoW.Me.Inventory.Equipped.MainHand.ItemInfo.WeaponClass != WoWItemWeaponClass.FishingPole;
            }
        }

        private static int MainHandPoison
        {
            get
            {
                switch (ClassSettings._Instance.SubtletyMainPoison)
                {

                    case ePoisonMainHand.Wound:
                        return 8679;
                    case ePoisonMainHand.Deadly:
                        return 2823;
                    default:
                        return 0;
                }
            }
        }

        private static int OffHandHandPoison
        {
            get
            {
                switch (ClassSettings._Instance.SubtletyOffHandPoison)
                {
                    case ePoisonOffHand.MindNumbing:
                        return 5761;
                    case ePoisonOffHand.Crippling:
                        return 3408;
                    case ePoisonOffHand.Paralytic:
                        return 108215;
                    case ePoisonOffHand.Leeching:
                        return 108211;
                    default:
                        return 0;
                }
            }
        }
        /* //Credit to CLU
         public static Composite CreateApplyPoisons()
         {
             return new PrioritySelector(
                        new Decorator(
                            ret => NeedsPoison && !StyxWoW.Me.HasAura(MainHandPoison) && SpellManager.HasSpell(MainHandPoison),
                            new Sequence(
                                new Action(ret => Navigator.PlayerMover.MoveStop()),
                                Spell.CreateWaitForLagDuration(),
                                new Action(ret => SpellManager.CastSpellById(MainHandPoison)),
                                Spell.CreateWaitForLagDuration(),
                                new WaitContinue(2, ret => StyxWoW.Me.IsCasting, new ActionAlwaysSucceed()),
                                new WaitContinue(10, ret => !StyxWoW.Me.IsCasting, new ActionAlwaysSucceed()),
                                new WaitContinue(1, ret => false, new ActionAlwaysSucceed()))),



                           new Decorator(
                            ret => NeedsPoison && !StyxWoW.Me.HasAura(OffHandHandPoison) && SpellManager.HasSpell(OffHandHandPoison),
                            new Sequence(
                                new Action(ret => Navigator.PlayerMover.MoveStop()),
                                Spell.CreateWaitForLagDuration(),
                                new Action(ret => SpellManager.CastSpellById(OffHandHandPoison)),
                                Spell.CreateWaitForLagDuration(),
                                new WaitContinue(2, ret => StyxWoW.Me.IsCasting, new ActionAlwaysSucceed()),
                                new WaitContinue(10, ret => !StyxWoW.Me.IsCasting, new ActionAlwaysSucceed()),
                                new WaitContinue(1, ret => false, new ActionAlwaysSucceed())))
                    );
         }*/
        public static void CreateApplyPoisons()
        {
            if (NeedsPoison && !StyxWoW.Me.HasAura(MainHandPoison) && SpellManager.HasSpell(MainHandPoison))
            {
                Navigator.PlayerMover.MoveStop();
                Spell.CreateWaitForLagDuration();
                SpellManager.CastSpellById(MainHandPoison);
                Spell.CreateWaitForLagDuration();
                Thread.Sleep(1500);


            }

            if (NeedsPoison && !StyxWoW.Me.HasAura(OffHandHandPoison) && SpellManager.HasSpell(OffHandHandPoison))
            {
                Navigator.PlayerMover.MoveStop();
                Spell.CreateWaitForLagDuration();
                SpellManager.CastSpellById(OffHandHandPoison);
                Spell.CreateWaitForLagDuration();
                Thread.Sleep(1500);
            }
        }
    }
}
